import pytest


class TestDemo:

    # @pytest.mark.skip('不想执行')
    @pytest.mark.usefixtures('driver')
    @pytest.mark.run(order=2)
    @pytest.mark.p0
    def test_01(self):
        print('这是用例01')
        assert 0 > 2

    # @pytest.mark.skipif(0 < 2, reason='条件为真，跳过')
    @pytest.mark.run(order=1)
    @pytest.mark.p0
    def test_02(self, driver):
        print('这是用例02')
        assert 0 < 2

    # @pytest.mark.flaky(reruns =5,reruns_delay=2)
    @pytest.mark.run(order=0)
    @pytest.mark.p0
    def test_03(self):
        print('这是用例03')
        assert 0 > 2


# if __name__ == '__main__':
#      pytest.main(['-vs'])
#         pwd: Aa123456
#   - account: admin
#     pwd: Aa123456
# yaml

'''使用parametrize传参'''
# login_data = [('admin','Aa123456!'),('admin','Aa123456')] # 测试数据
# @pytest.mark.parametrize('a',login_data,ids=['case1','case2'])
# def test_crmeb_admin_login(a):
#     data = {
#         'url': "http://47.95.213.187:8899/adminapi/login",
#         'method': "post",
#         'headers': {'content-type': "application/json;charset=UTF-8"},
#         'json': {"account": a[0], "pwd": a[1], "imgcode": "1"}
#
#     }
#     res = requests.request(**data)
#     print(res.request.body)
#     assert res.status_code==200

'''使用夹具传参'''
# def test_crmeb_admin_login(logindata):
#     data = {
#         'url': "http://47.95.213.187:8899/adminapi/login",
#         'method': "post",
#         'headers': {'content-type': "application/json;charset=UTF-8"},
#         'json': {"account": logindata[0], "pwd": logindata[1], "imgcode": "1"}
#
#     }
#     res = requests.request(**data)
#     print(res.request.body)
#     assert res.status_code==200

'''使用yaml文件传参'''


# def login_data_load():
#     with open('./data.yaml', 'r') as f:
#         data = yaml.safe_load(f)
#     return data['login_data']
#
#
# @pytest.mark.parametrize('login_info', login_data_load())
# def test_crmeb_admin_login(login_info):
#     data = {
#         'url': "http://47.95.213.187:8899/adminapi/login",
#         'method': "post",
#         'headers': {'content-type': "application/json;charset=UTF-8"},
#         'json': {"account": login_info['account'], "pwd": login_info['pwd'], "imgcode": "1"}
#
#     }
#     res = requests.request(**data)
#     print(res.request.body)
#     assert res.status_code == 200
cope='session',name='driver')
def setup_teardown_func():
    print('测试用例执行前的操作')
    yield
    print('测试用例执行后的操作')


@pytest.fixture(scope='session',params=[('admin','Aa123456!'),('admin','Aa123456')])
def logindata(request): # 创建参数夹具
    return request.param
